<!DOCTYPE html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml" xmlns:v-model="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>13demo</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>

<div id="app">
    num={{g_num}}
    <counter v-on:plus="gNumPlus"  v-on:reduce="gNumReduce" v-bind:num="g_num"> </counter>
</div>
<script type = "text/javascript">

    //定义组件
    const counter = {
        template:`
        <div>
        <button v-on:click="numPlus">增加</button>
        <button v-on:click="numReduce">减少</button>
        </div>
        </div>
         `,
        data(){
            return{num:1}
        },
        methods: {
            numPlus() {
                console.log("num="+this.num);
                return this.$emit("plus");
            },
            numReduce(){
                console.log("num="+this.num);
                return this.$emit("reduce");
            }
        }

    }

    //注册组件
    Vue.component("counter",counter)

    var app=new Vue({
         el:"#app",
        data:{
             g_num:0
        },
        methods:{
             gNumPlus(){
                 this.g_num++;
             }
             gNum
        }

    })
</script>
</body>
</html>